package com.wf.netty.link;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * 功能描述
 *
 * @author wf
 * @since 2022/5/12
 */
public class ServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        msg = "server handler";
        ctx.channel().writeAndFlush(msg);
        System.out.println("step into ServerHandler");
    }

//    @Override
//    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
//        System.out.println("服务端接收完成");
//    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
        if (cause != null) {
            System.out.println(cause.getMessage());
        }
    }
}
